package app.sb.jly.com.ji_liang_yuan.activitys.ac;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import app.sb.jly.com.ji_liang_yuan.R;
import app.sb.jly.com.ji_liang_yuan.activitys.application.BaseApplication;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.Constants;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.PDALogUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.UtilsLog;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//参考车辆信息
public class MainActivity extends BaseActivity {

    @BindView(R.id.ac_cankao_gaosu_jianding)
    Button acCankaoGaosuJianding;
    @BindView(R.id.ac_cankao_feixian_jianding)
    Button acCankaoFeixianJianding;
    @BindView(R.id.ac_cankao_title)
    TextView acCankaoTitle;
    String carModel = "", carModelA = "", carModelB = "";
    String zhoushuText = "", zhoushuAText = "",zhoushuBText = "";
    int zhoushu = 0, zhoushuA = 0, zhoushuB = 0;
    int result = 0,resultA = 0, resultB = 0;
    int in_type = 0;
    String zhizaodanwei = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
//        setTopTitle("参考车辆信息");
//        setBackBtn();

//        UtilsLog.e("111111111111");
//        setTxtContents("济南");
//        UtilsLog.e("22222222222");

    }

    void setTxtContents(String fileName) {
        String str = "";
        for (int i = 0; i < Constants.contents.length; i++) {
            str += Constants.contents[i] + "\n";
        }
        UtilsLog.e(str);
//        String logStrf = "\n" + "onCreate-----登陆-------" + "\n";
        PDALogUtils.createTxtFile(fileName, str.getBytes(), this);
    }

    @OnClick({R.id.ac_cankao_gaosu_jianding, R.id.ac_cankao_feixian_jianding, R.id.ac_cankao_title})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_cankao_gaosu_jianding:
                //高速检定
                if (in_type == 0){
                    Toast.makeText(this,"请先补全参考车辆信息",Toast.LENGTH_LONG).show();
                }else{
                    Intent intent = new Intent(this, JiZhongCaiJiActivity.class);
                    intent.putExtra("type", "高速检定");
                    intent.putExtra("carModel", carModel);
                    intent.putExtra("carModelA", carModelA);
                    intent.putExtra("carModelB", carModelB);
                    intent.putExtra("zhoushu", zhoushu);
                    intent.putExtra("zhoushuA", zhoushuA);
                    intent.putExtra("zhoushuB", zhoushuB);
                    intent.putExtra("result",result);
                    intent.putExtra("resultA",resultA);
                    intent.putExtra("resultB",resultB);
                    intent.putExtra("in_type", in_type);
                    intent.putExtra("zhizaodanwei", zhizaodanwei);
                    startActivity(intent);
                }
                break;
            case R.id.ac_cankao_feixian_jianding:
                //非现检定
                if (in_type == 0){
                    Toast.makeText(this,"请先补全参考车辆信息",Toast.LENGTH_LONG).show();
                }else {
                    Intent intent2 = new Intent(this, JiZhongCaiJiActivity.class);
                    intent2.putExtra("type", "非现检定");
                    intent2.putExtra("carModel", carModel);
                    intent2.putExtra("carModelA", carModelA);
                    intent2.putExtra("carModelB", carModelB);
                    intent2.putExtra("zhoushu", zhoushu);
                    intent2.putExtra("zhoushuA", zhoushuA);
                    intent2.putExtra("zhoushuB", zhoushuB);
                    intent2.putExtra("result",result);
                    intent2.putExtra("resultA",resultA);
                    intent2.putExtra("resultB",resultB);
                    intent2.putExtra("in_type", in_type);
                    intent2.putExtra("zhizaodanwei", zhizaodanwei);
                    startActivity(intent2);
                }
                break;
            case R.id.ac_cankao_title:
                //title
                Intent intent3 = new Intent(this, SelectActivity.class);
                startActivityForResult(intent3, 201);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 201 && resultCode == RESULT_OK){
            in_type = data.getExtras().getInt("in_type");
            if (in_type == 1){
                carModel = data.getExtras().getString("carModel");
                zhoushu = data.getExtras().getInt("zhoushu");
                result = data.getExtras().getInt("result");
                zhoushuText = data.getExtras().getString("zhoushuText");
                zhizaodanwei = data.getExtras().getString("zhizaodanwei");
                BaseApplication.myCheckDataModel.setType0(carModel);
                BaseApplication.myCheckDataModel.setType1("/");
                BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushu));
                BaseApplication.myCheckDataModel.setZhoushu1("/");
                BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(result));
                BaseApplication.myCheckDataModel.setZhongliang1("/");
                BaseApplication.myCheckDataModel.setWholeInfo(zhoushuText+"刚性");
            }else if(in_type == 2){
                carModel = data.getExtras().getString("carModel");
                zhoushu = data.getExtras().getInt("zhoushu");
                result = data.getExtras().getInt("result");
                zhoushuText = data.getExtras().getString("zhoushuText");
                zhizaodanwei = data.getExtras().getString("zhizaodanwei");
                BaseApplication.myCheckDataModel.setType0("/");
                BaseApplication.myCheckDataModel.setType1(carModel);
                BaseApplication.myCheckDataModel.setZhoushu0("/");
                BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushu));
                BaseApplication.myCheckDataModel.setZhongliang0("/");
                BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(result));
//                BaseApplication.myCheckDataModel.setWholeInfo(zhoushuText+"刚性");
            }else if (in_type == 3){
                carModelA = data.getExtras().getString("carModelA");
                zhoushuA = data.getExtras().getInt("zhoushuA");
                resultA = data.getExtras().getInt("resultA");
                carModelB = data.getExtras().getString("carModelB");
                zhoushuB = data.getExtras().getInt("zhoushuB");
                resultB = data.getExtras().getInt("resultB");
                zhoushuAText = data.getExtras().getString("zhoushuAText");
                zhoushuBText = data.getExtras().getString("zhoushuBText");
                zhizaodanwei = data.getExtras().getString("zhizaodanwei");
                BaseApplication.myCheckDataModel.setType0(carModelA);
                BaseApplication.myCheckDataModel.setType1(carModelB);
                BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushuA));
                BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushuB));
                BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(resultA));
                BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(resultB));
                BaseApplication.myCheckDataModel.setWholeInfoA(zhoushuAText+carModelA);
//                BaseApplication.myCheckDataModel.setWholeInfoB(zhoushuBText+carModelB);
            }
//            carModel = data.getExtras().getString("carModel");
//            zhoushu = data.getExtras().getInt("zhoushu");
//            result = data.getExtras().getInt("result");
//            zhizaodanwei = data.getExtras().getString("zhizaodanwei");
//            BaseApplication.myCheckDataModel.setType0(carModel);
//            BaseApplication.myCheckDataModel.setType1(carModel);
//            BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushu));
//            BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushu));
//            BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(result));
//            BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(result));
        }
    }
}
